# 単体テスト用のアサート

assert_true <- function( condition, message )
{
	if ( is.na( condition ) )
	{
		print( "assert_true fail, condition is na\n\t", message, sep="" )
		return( 0 )
	}
	if ( condition == FALSE )
	{
		cat( "assert_true fail\n\t", message, "\n", sep="" )
	}
}

assert_equals <- function( expected, actual, message )
{
	if ( is.na( expected ) )
	{
		print( "assert_equals fail, expected is na\n\t", message, sep="" )
		return( 0 )
	}
	if ( is.na( actual ) )
	{
		print( "assert_equals fail, actual is na\n\t", message, sep="" )
		return( 0 )
	}

	if ( expected != actual )
	{
		cat( "assert_equals fail\n\t", message, "\n\texpected: ", expected, ", actual: ", actual, ".\n", sep="" )
	}
} 

assert_numeric_equals <- function( expected, actual, precision, message )
{
	if ( is.na( expected ) )
	{
		print( "assert_numeric_equals fail, expected is na\n\t", message, sep="" )
		return( 0 )
	}
	if ( is.na( actual ) )
	{
		print( "assert_numeric_equals fail, actual is na\n\t", message, sep="" )
		return( 0 )
	}
	if ( is.na( precision ) )
	{
		print( "assert_numeric_equals fail, error is na\n\t", message, sep="" )
		return( 0 )
	}

	if ( abs( expected - actual ) >= precision )
	{
		cat( "assert_numeric_equals fail\n\t", message, "\n\texpected: ", expected, ", actual: ", actual,
			 ", error: ", abs( expected - actual ), ", precision: ", precision, ".\n", sep="" )
	}
}
